import {BasicColumn, FormSchema} from '/@/components/Table';
import {render} from '/@/utils/common/renderUtils';
import {DescItem} from '/@/components/Description/index';

export const columns: BasicColumn[] = [
  {
    title: '头像',
    dataIndex: 'avatar',
    width: 80,
    customRender: (record) => {
      return render.renderAvatar(record)
    },
  },
  {
    title: '用户账号',
    dataIndex: 'userName',
    width: 100,
  },
  {
    title: '用户姓名',
    dataIndex: 'realName',
    width: 100,
  },
  {
    title: '租户名称',
    dataIndex: 'tenantName',
    width: 100,
  },
  {
    title: '拥有者',
    width: 60,
    customRender: ({text}) => {
      let showText = '是'
      let color = 'green'
      if (!text) {
        color = 'red'
        showText = '否'
      }
      return render.renderTag(showText, color)
    },
    dataIndex: 'isOwner'
  },
  {
    title: '状态',
    dataIndex: 'status',
    customRender: ({text}) => {
      let color = 'green'
      if (text === '2') {
        color = 'red'
      }
      return render.renderTag(render.renderDict(text, 'user_status'), color)
    },
    width: 60,
  },
  {
    title: '添加时间',
    dataIndex: 'addTime',
    width: 140,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '账号',
    field: 'userName',
    componentProps: {
      placeholder: '用户账号',
    },
    component: 'Input',
  },
  {
    label: '用户状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode:'user_status',
      placeholder:'请选择状态',
      stringToNumber:true
    }
  }
];


export const formDetailSchema: DescItem[] = [
  {
    field: 'avatar',
    label: '头像',
    render: (curVal, data) => {
      return render.renderAvatar({ record : {avatar: curVal} })
    },
  },
  {
    field: 'userName',
    label: '用户名',
  },
  {
    field: 'tenantId',
    label: '租户ID',
  },
  {
    field: 'tenantName',
    label: '租户名称'
  },
  {
    field: 'isOwner',
    label: '拥有者',
    render: (curVal, data) => {
      let showText = '是'
      let color = 'green'
      if (!curVal) {
        color = 'red'
        showText = '否'
      }
      return render.renderTag(showText, color)
    },
  },
  {
    field: 'lastLoginIp',
    label: '最后登录IP'
  },
  {
    field: 'lastLoginTime',
    label: '最后登录时间'
  },
  {
    field: 'addTime',
    label: '添加时间'
  }
];

